Use gsk for text shadows
authorMatthias Clasen <mclasen@redhat.com>
Fri, 1 Sep 2017 19:33:27 +0000 (15:33 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 1 Sep 2017 19:34:13 +0000 (15:34 -0400)
We don't need to render these manually using cairo anymore.

gtk/gtksnapshot.c

index 11e594ea84994c468ae69a8442fb622bb7cc8fe1..0408a70fc81d97135261309fe065ab07fee6e3c5 100644 (file)
@@ -1332,7 +1332,9 @@ gtk_snapshot_render_layout (GtkSnapshot     *snapshot,
                             PangoLayout     *layout)
 {
   const GdkRGBA *fg_color;
-  GtkCssValue *shadow;
+  GtkCssValue *shadows_value;
+  GskShadow *shadows;
+  gsize n_shadows;
 
   g_return_if_fail (snapshot != NULL);
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
@@ -1342,32 +1344,19 @@ gtk_snapshot_render_layout (GtkSnapshot     *snapshot,
 
   fg_color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR));
 
-  shadow = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_TEXT_SHADOW);
-  if (!_gtk_css_shadows_value_is_none (shadow))
-    {
-      PangoRectangle ink_rect;
-      graphene_rect_t bounds;
-      GtkBorder shadow_extents = { 0, };
-      cairo_t *cr;
-
-      pango_layout_get_pixel_extents (layout, &ink_rect, NULL);
-      _gtk_css_shadows_value_get_extents (shadow, &shadow_extents);
-      graphene_rect_init (&bounds,
-                          ink_rect.x - shadow_extents.left,
-                          ink_rect.y - shadow_extents.top,
-                          ink_rect.width + shadow_extents.left + shadow_extents.right,
-                          ink_rect.height + shadow_extents.top + shadow_extents.bottom);
+  shadows_value = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_TEXT_SHADOW);
+  shadows = gtk_css_shadows_value_get_shadows (shadows_value, &n_shadows);
+  if (shadows)
+    gtk_snapshot_push_shadow (snapshot, shadows, n_shadows, "TextShadow<%zu>", n_shadows);
 
-      cr = gtk_snapshot_append_cairo (snapshot, &bounds, "Text<%dchars>", pango_layout_get_character_count (layout));
-
-      gdk_cairo_set_source_rgba (cr, fg_color);
+  gsk_pango_show_layout (snapshot, fg_color, layout);
 
-      _gtk_css_shadows_value_paint_layout (shadow, cr, layout);
-      cairo_destroy (cr);
+  if (shadows)
+    {
+      gtk_snapshot_pop (snapshot);
+      g_free (shadows);
     }
 
-  gsk_pango_show_layout (snapshot, fg_color, layout);
-
   gtk_snapshot_offset (snapshot, -x, -y);
 }